package com.kk.cart.listener;

import com.kk.cart.service.CartService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * projectName: b2c-store
 *
 * @author: kjy
 * time: 2023/5/10 16:41
 * description: 监听mq消息
 */
@Component
public class CartRabbitListener {

    @Autowired
    private CartService cartService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "clear.queue"),
            exchange = @Exchange(name = "topic.ex"),
            key = "clear.cart"
    ))
    public void clear(List<Integer> cartIds){

        cartService.clearIds(cartIds);
    }
}
